package com.vhall.component.service.pay.impl;

import com.vhall.component.plugin.core.service.PaasService;
import com.vhall.component.service.pay.NotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * @author lsl
 * @since 2021/7/5
 */
@Service
@Slf4j
public class NotifyServiceImpl implements NotifyService {

    private static final String OPTIONAL = "optional";
    private static final String SUCCESS = "success";

    @Value("${vhall.pay.domain}")
    private String api;

    @Resource
    PaasService paasService;

    @Override
    public String payNotify(Map<String, Object> params) {
        log.info("支付回调开始:params:{}", params);
        String url = "";
        if (Objects.equals(params.get(OPTIONAL), "reward")) {
            // 判断打赏的支付状态
            url = api + "/v4/reward/inner/set-pay-status";
        } else if (Objects.equals(params.get(OPTIONAL), "gift")) {
            // 判断表情的支付状态
            url = api + "/v4/gift/set-pay-status";
        } else if (Objects.equals(params.get(OPTIONAL), "red_packet")) {
            // 判断红包的支付状态
            url = api + "/v4/redpacket/inner/pay-status-set";
        }

        boolean payStatus = paasService.sendPayStatusParams(params, url);
        if (payStatus) {
            return SUCCESS;
        }

        return "failure";
    }


}
